<%--
  Created by IntelliJ IDEA.
  User: cjegzfz
  Date: 2020/9/3
  Time: 7:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page trimDirectiveWhitespaces="true"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName()
            + ":" + request.getServerPort() + path + "/";
%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <link href="<%=basePath%>Css/Content.css" rel="stylesheet" type="text/css" />
    <!-- Bootstrap Core CSS -->
    <link href="<%=basePath%>Css/bootstrap.min.css" rel="stylesheet" />
    <link href="<%=basePath%>Css/button.css" rel="stylesheet" type="text/css" />
    <link href="<%=basePath%>Css/dataTables.bootstrap.css" rel="stylesheet" />
    <link href="<%=basePath%>Css/metisMenu.min.css" rel="stylesheet" />
    <!-- 引入js文件 -->
    <!-- jQuery -->
    <script src="<%=basePath%>js/jquery-1.11.3.min.js"></script>
    <!-- Bootstrap Core JavaScript -->
    <script src="<%=basePath%>js/bootstrap.min.js"></script>
    <!-- Metis Menu Plugin JavaScript -->
    <script src="<%=basePath%>js/metisMenu.min.js"></script>
    <!-- DataTables JavaScript -->
    <script src="<%=basePath%>js/jquery.dataTables.min.js"></script>
    <script src="<%=basePath%>js/dataTables.bootstrap.min.js"></script>

    <!-- Custom Theme JavaScript -->
    <script src="<%=basePath%>js/sb-admin-2.js"></script>
    <script type="text/javascript">
        function deleteUser(id) {
            if(confirm('确实要删除该信息吗?')){
                $.post("<%=basePath%>/deleteUser.action",{"id":id},
                    function (data) {
                        if (data == "OK"){
                            alert("删除成功！");
                            window.location.reload();
                        }
                        else {
                            alert("删除失败！");
                            window.location.reload();
                        }
                    }
                )
            }
        }
        //此js用于将数据填入修改模态框中作为初始值
        function editUser(id) {
            $.ajax({
                type: "get",
                url: "<%=basePath%>/getUserById.action",
                data: {"id": id},
                success: function (data) {
                    console.log(data)
                    $("#id").val(data.id);
                    $("#username").val(data.username);
                    $("#studentClass").val(data.studentClass);
                    $("#sex").val(data.sex);
                    $("#address").val(data.address);
                    $("#phone").val(data.phone);

                }
            });
        }

            function addLoan() {
                $.post("<%=basePath%>/addUser.action",$("#add_loan_form").serialize(),
                    function (data) {
                        if (data=="OK"){
                            alert("创建成功!");
                            window.location.reload();
                        }else {
                            alert("创建失败！");
                            window.location.reload();
                        }
                    }
                );
        }
    function updateUser() {
        $.post("<%=basePath%>/updateUser.action  ",$("#edit_loan_form").serialize(),function (data) {
            if(data =="OK"){
                alert("更新成功！");
                window.location.reload();
            }else{
                alert("更新失败！");
                window.location.reload();
            }
        })
    }
    </script>
</head>
<body>

<div class="div_top">学生信息管理 &gt; 学生信息管理</div>
<div class="row" style="margin-top: 20px">
    <div class="col-sm-3"></div>
    <div class="col-sm-6">
            <form class="form-search" method="get" action="<%=basePath%>/findUserBystudentClass.action">
                <div class="input-group">
                <input  class="form-control" type="text"  placeholder="请输入班级" name="studentClass"/>
                <span class="input-group-btn">
                    <button class="btn" type="submit">查找</button>
                </span>
                </div>
            </form>
    </div>
<div class="col-sm-3"></div>
</div>
<div >

    <table class="table table-striped">
        <thead>
        <tr>
            <th>编号</th><th>用户</th><th>班级</th><th>性别</th><th>籍贯</th><th>电话</th><th>操作</th>
        </tr>
        </thead>
        <tbody>
        <c:forEach items="${Users}" var="user">

            <tr >
                <td>
                    ${user.id}
                </td>
                <td>${user.username}</td>
                <td>${user.studentClass}</td>
                <td>${user.sex}</td>
                <td>${user.address}</td>
                <td>${user.phone}</td>

                <td>
                    <a class="button button-box button-small button-longshadow-right button-primary" onclick="deleteUser(${user.id})">删除</a>&nbsp;&nbsp;
                    <a  class="button button-box  button-small button-longshadow-right button-primary" data-toggle="modal" data-target="#loanEditDialog" onclick="editUser(${user.id})">修改</a>
                </td>

            </tr>
        </c:forEach>
        </tbody>
    </table>

</div>

<div class="modal fade" id="loanEditDialog" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改客户信息</h4>
            </div>
        <div class="modal-body">
            <form class="form-horizontal" id="edit_loan_form">
                <input type="hidden" id="edit_The_loan_id" name="The_loan_id"/>
                <div class="form-group">
                    <label for="id" class="col-sm-2 control-label">
                        编号
                    </label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control"id="id" placeholder="编号" name="id" readonly="readonly">
                    </div>
                </div>
                <div class="form-group">
                    <label for="username" class="col-sm-2 control-label">
                        姓名
                    </label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="username" placeholder="姓名" name="username">
                    </div>

                </div>
                <div class="form-group">
                <label for="studentClass" class="col-sm-2 control-label">
                    班级
                </label>
                <div class="col-sm-10">
                    <input type="text" class="form-control" id="studentClass" placeholder="班级" name="studentClass">
                </div>
                </div>

                <div class="form-group">
                    <label for="sex" class="col-sm-2 control-label">
                        性别
                    </label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="sex" placeholder="性别" name="sex">
                    </div>
                </div>

                <div class="form-group">
                    <label for="address" class="col-sm-2 control-label">
                        地址
                    </label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="address" placeholder="地址" name="address">
                    </div>
                </div>

                <div class="form-group">
                    <label for="phone" class="col-sm-2 control-label">
                       电话
                    </label>
                    <div class="col-sm-10">
                        <input type="text" class="form-control" id="phone" placeholder="电话" name="phone">
                    </div>
                </div>
            </form>
        </div>
        <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" class="btn btn-primary" onclick="updateUser()">保存修改</button>
        </div>
        </div>
    </div>
    <%--模态框结束--%>


    <%--模态框结束--%>

</div>
</body>
</html>

